package com.huawei.su;

import java.util.HashMap;
import java.util.Map;

public class BM51 {
    public static void main(String[] args) {

    }

    public int MoreThanHalfNum_Solution(int[] numbers) {
        // write code here
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < numbers.length; i++) {
            if (map.containsKey(numbers[i])) {
                map.put(numbers[i], map.get(numbers[i]) + 1);
                if (2 * map.get(numbers[i]) > numbers.length) {
                    return numbers[i];
                }
            } else {
                map.put(numbers[i], 1);
            }
        }
        return map.keySet().iterator().next();
    }
}
